package com.eazy.lkv2.web.controller.system;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.eazy.lkv2.web.controller.BaseController;
import com.eazy.lkv2.web.service.system.SystemLogService;

/**
 * @author jzx
 * @desc 系统登录处理类
 * @date 2016.6.3
 */
@Controller
@RequestMapping("/system")
public class LoginController extends BaseController {

	@Autowired
	private SystemLogService systemLogService;
	
	@RequestMapping(value = "/login",method = RequestMethod.GET)
	public String login() {
		return "redirect:index";
	}
	
	/**
	 * 跳转到首页
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public ModelAndView index() {
		return new ModelAndView("system/index");
	}
	
	/**
	 * 跳转到欢迎页
	 */
	@RequestMapping(value = "/welcome", method = RequestMethod.GET)
	public ModelAndView welcome() {
		
		List<Map<String,Object>> data = null;
		
		data = systemLogService.select();
		
		ModelAndView model = new ModelAndView("system/welcome");
		
		model.addObject("data", data);
		model.addObject("count", data.size());
		
		model.addObject("ip", "");
		model.addObject("last_time", "");
		
		// 获取当前时间第一个登录用户
		if(data != null) {
			model.addObject("ip", data.get(0).get("IP"));
			model.addObject("last_time", data.get(0).get("tim"));
		} 
		
		return model;
	}
}
